package class202204._21_25;

/**
 * 类与对象
 */
//一个java文件不能有两个public(类)
//定义类就是class+类名---->大驼峰  由两部分组成 属性+方法
class Person{
    //1、属性[成员变量]   定义在类当中 方法的外边
    public String name;
    public int age;

    //2、方法[成员方法]
    public void sleep(){
        System.out.println("睡觉！");
    }
    public void eat(){
        System.out.println("吃饭！");
    }
}
//定义一个类
class Student {
    //成员变量
    public String name ;
    public int age  ;
    public double score ;
    public String sex ;


    public Student(){
        //调用本类中带有两个参数的构造方法  第一个参数类型是String 第而个参数类型Int
        this("zhangwei",18);
        System.out.println("这是一个不带参数的构造方法！");
    }
    public Student(String name,int age){
        this.age = age;
        this.name = name;
        System.out.println("这是一个带两个参数的构造方法！");
    }

    public Student(String name, int age, double score, String sex) {
        this.name = name;
        this.age = age;
        this.score = score;
        this.sex = sex;
        System.out.println("这是带有四个参数的构造函数！");
    }

    //方法
    public void doClass(){
        System.out.println(name+"上课！");
    }
    public void doHOMEWORK(){
        System.out.println(name+"写作业！");
    }

    public void show() {
        System.out.println(" 姓名："+name+" 年龄："+age+" 学分："+score+" 性别："+sex );
    }
}
//描述一下你女朋友，类
class MyGirFired{
    public String name;
    public int age;
    public String eyes;

    public void eat(){
        System.out.println("吃火锅！");
    }
}
public class demo20220424 {


    public static void main(String[] args) {
        Student student = new Student();
        student.show();
    }



    public static void main4(String[] args) {
        Student student = new Student("zahngwei",18);
        student.show();
        Student student2 = new Student("zahngwei2",18,99.9,"男");
        student2.show();

        /*Student student = new Student();
        student.age = 10;
        student.name = "xaio";
        student.score = 1;
        student.show();*/
    }


    public static void main1(String[] args) {
        int a = 10;
        //实例化一个对象[通过new关键字创建了一个对象]
        Person person = new Person();
    }
    public static void main2(String[] args) {
        Student student1 = new Student();//学生   对象/实体
        //new 关键字
        MyGirFired myGirFired = new MyGirFired();//实体化女朋友对象
    }

    public static void main3(String[] args) {
        //类名  变量 = new 类名（）；    实例化对象
        Student student = new Student();
        //如何访问成员变量呢
         student.age = 10;
         student.name = "wei";
         student.score = 9.9;
         student.sex = "男";
         student.doClass();
         student.doHOMEWORK();
         student.show();


        System.out.println("=======");
        Student student5 = new Student();
        student5.show();

//        int a;    需要初始化
//        System.out.println(a);


        System.out.println("=======================");
         Student student2 = new Student();
         student2.name = "weizhen";
         student2.age = 19;
         student2.score = 99.9;
         student2.sex = "男";
        student.doClass();
        student.doHOMEWORK();
         student2.show();

    }
}
 